package WaiBao;

import java.util.Arrays;

public class Zhangqi1 {
    public static void main(String[] args) {
        String[] name = {"刘晓燕(班长)", "李霞为(副班长)", "小李(学习委员)", "王遗风(团支书)", "王熙凤", "贾宝玉", "林黛玉", "钟意", "薛宝才", "李戴", "胡慧珍", "文君",
                "薛宝钗", "何国秀", "杨迪", "何炅", "将华宇", "刘梅", "康仔", "李晓梅", "杜小兰", "李小春", "张瑶瑶", "胡橘芳", "王波", "力扣", "沈霞", "彭海燕",
                "郭敬明", "张琦(学生)"};//考生本人:张琦(学生)
        int[] age = {20, 19,18, 18,22, 19, 20, 20, 19, 21,21, 20, 18, 20, 18, 19, 18, 20, 18, 18, 20, 19, 21, 20, 20, 18, 21, 20, 19,20};//考生年龄：20岁

        double[] haidao1 = {78, 84, 85, 90, 80, 69, 78, 59, 60, 70, 91, 87, 84, 79, 64, 68, 69, 99, 96, 88, 92, 91, 95, 85, 75, 74, 74, 84, 89, 82};
        double[] haidao2 = {64, 74, 77, 69, 68, 97, 88, 89, 90, 90, 80, 65, 86, 76, 65, 65, 86, 79, 66, 78, 82, 71, 85, 85, 75, 88, 75, 79, 85, 83};
        double[] haidao3 = {88, 85, 89, 95, 75, 99, 69, 89, 80, 60, 93, 87, 85, 85, 69, 98, 89, 79, 96, 63, 92, 81, 95, 85, 76, 88, 73, 78, 78, 94};

        double chuan1;//代表每个学生的总分
        double chuan2;//代表每个学生的平均分
//        for (int i = 0; i < 30; i++) {
//            chuan1 = haidao1[i] + haidao2[i] +haidao3[i];
//            chuan2 = (chuan1* 1.0) / 3;
//            System.out.println(name[i] + "的总分为:" + chuan1);
//            System.out.println(name[i] + "的平均分为:" +chuan2);
//        }


//        double ret1 = 0, ret2 = 0;
//        double[] a = new double[30];
//        for (int i = 0; i < 30; i++) {
//            ret1 = haidao1[i] + haidao2[i] + haidao3[i];
//            ret2 = (ret1 * 1.0) / 3;
//            a[i] = ret2;
//        }
//
//        for (int i = 0; i < a.length - 1; i++) {
//            for (int j = 0; j < a.length - i - 1; j++) {
//                if (a[j] < a[j + 1]) {
//                    double temp = a[j];
//                    a[j] =a[j + 1];
//                    a[j + 1] = temp;
//                }
//            }
//        }
//        System.out.println("前十名同学的成绩为:");
//        for (int i = 0; i < 10; i++) {
//            System.out.println(a[i]);
//        }


        double men1 = 0, men2 = 0, men3 = 0;//计算每门课的平均分
        double dang1 = 0,dang2 = 0, dang3 = 0;//计算每门课标准差
        double hu1 = 0,hu2 = 0,hu3 = 0;//计算每门课中位数
        double sum2 = 0;
        for (int i = 0; i < haidao1.length; i++) {
            sum2+=haidao1[i];
        }
        men1 = (sum2*1.0)/30;
        System.out.println("分析化学的班级平均分为:"+men1);
        double Sum = 0;
        for (int i = 0; i < haidao2.length; i++) {
            Sum+=haidao2[i];
        }
        men2 = (Sum*1.0)/30;
        System.out.println("线性代数的班级平均分为:"+men2);
        double sum = 0;
        for (int i = 0; i <haidao3.length; i++) {
            sum+=haidao3[i];
        }
        men3 = (sum*1.0)/30;
        System.out.println("有机化学的班级平均分为:"+men3);



        double c1 = 0,c2 = 0,c3 = 0;
        for (int i = 0; i < haidao1.length; i++) {
            c1+= (haidao1[i] - men1)*(haidao1[i] - men1);
        }
        dang1 = Math.sqrt(c1*1.0/30);
        System.out.println("分析化学的班级标准差为:"+dang1);

        for (int i = 0; i < haidao2.length; i++) {
            c2+= (haidao2[i] - men2)*(haidao2[i] - men2);
        }
        dang2 = Math.sqrt(c2*1.0/30);
        System.out.println("线性代数的班级标准差为:"+dang2);

        for (int i = 0; i < haidao3.length; i++) {
            c3+= (haidao3[i] -men3)*(haidao3[i] - men3);
        }
        dang3 = Math.sqrt(c3*1.0/30);
        System.out.println("有机化学的班级标准差为:"+dang3);
//
        Arrays.sort(haidao1);
        Arrays.sort(haidao2);
        Arrays.sort(haidao3);
        hu1 =( haidao1[15]+haidao1[14])*1.0/2;
        hu2 =( haidao2[15]+haidao2[14])*1.0/2;
        hu3 =( haidao3[15]+haidao3[14])*1.0/2;
        System.out.println("分析化学的中位数为:"+hu1);
        System.out.println("线性代数的中位数为:"+hu2);
        System.out.println("有机化学的中位数为:"+hu3);


    }
}
